package com.easyCode.sqlMapper.mapInfoAdaptor;
import com.easyCode.sqlBuilder.SqlInfo;
import com.easyCode.sqlBuilder.sqlInfo.BaseDataBaseSqlInfo;
import com.easyCode.sqlMapper.mapInfo.DataBaseMapInfo;
import java.util.stream.Collectors;


/**
 * @author 大忽悠
 * @create 2022/12/2 14:50
 */
public class DataBaseMapInfoAdaptor implements MapInfoAdaptor<DataBaseMapInfo> {
    private final TableMapInfoAdaptor tableMapInfoAdaptor=new TableMapInfoAdaptor();

    /**
     * @param source sqlInfo子类
     * @return 当前适配器是否支持适配当前sqlInfo
     */
    @Override
    public boolean support(SqlInfo source) {
        return source instanceof BaseDataBaseSqlInfo;
    }

    /**
     * @param source sqlInfo子类
     * @return mapInfo子类
     */
    @Override
    public DataBaseMapInfo adapter(SqlInfo source) {
        BaseDataBaseSqlInfo mysqlDataBaseSqlInfo = (BaseDataBaseSqlInfo) source;
        return DataBaseMapInfo.builder().dataBaseName(mysqlDataBaseSqlInfo.getDataBaseName())
                .tableMapInfos(mysqlDataBaseSqlInfo.getTableSqlInfoList().stream().map(tableMapInfoAdaptor::adapter).collect(Collectors.toList()))
                .build();
    }
}
